package com.lzkj.baotouhousingfund.utils;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;

import com.lzkj.baotouhousingfund.R;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.filter.Filter;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import java.util.List;

/**
 * @author Chengs
 * @Description: 选择图片 封装  方便之后更换库
 * @date 2017/12/28 17:14
 */
public class ChoosePicture {

    /**
     * @param activity
     * @param maxSelectable 设置最多选择图片数量
     */
    public static void start(Activity activity, int maxSelectable, int requestCode) {
        Matisse.from(activity)
                .choose(MimeType.ofImage(), false)
                .countable(true)
                .capture(true)
                .captureStrategy(
                        new CaptureStrategy(true, "com.lzkj.baotouhousingfund.fileprovider"))
                .maxSelectable(maxSelectable)
                .addFilter(new GifSizeFilter(320, 320, 5 * Filter.K * Filter.K))
                .gridExpectedSize(activity.getResources()
                        .getDimensionPixelSize(R.dimen.grid_expected_size))
                .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
                .thumbnailScale(0.85f)
                .imageEngine(new GlideEngine())
                .forResult(requestCode);
    }

    /**
     * 返回图片url
     *
     * @param data onActivityResult  Intent
     * @return
     */
    public static List<String> getImageUrl(Intent data) {
        return Matisse.obtainPathResult(data);
    }
}
